package codetop.greedy;

public class Code045 {
    public int jump(int[] nums) {
        if(nums.length==1)return 0;
        int step=1;
        int k=nums[0];
        int next_k=0;
        for (int i = 1; i <= k; i++) {
            if (k>=nums.length-1)break;
            int max=nums[i]+i;
            next_k=Math.max(max,next_k);
            if (i==k){
                k=next_k;
                step++;
            }
        }
        return step;
    }
}
